package com.dycong.common.leetcode.any;

public class BinaryString {

    public static void main(String[] args) {
        BinaryString binaryString = new BinaryString();
        System.out.println(binaryString.toBinaryString(0));
        System.out.println(binaryString.toBinaryString(1));
        System.out.println(binaryString.toBinaryString(2));
        System.out.println(binaryString.toBinaryString(3));
        System.out.println(binaryString.toBinaryString(4));
    }

    public String toBinaryString(int i) {
        StringBuilder builder = new StringBuilder();
        while (i != 0) {
            int bit = i & 1;
            builder.append(bit);
            i >>= 1;
        }
        return builder.reverse().toString();
    }
}
